/*******************************************************************************
 * Copyright (c) 2010 Mikhail Garber.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License (LGPL)
 * which accompanies this distribution
 * 
 * Contributors:
 *     Mikhail Garber - initial API and implementation
 ******************************************************************************/
package plumber.common;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;


/**
 * abstract parent class for various things that have GUID ids
 *
 */
public abstract class WithId implements Serializable {

	
	private static final long serialVersionUID = 6926968445712326839L;
	
	private String id = UUID.randomUUID().toString();
	private Date created = new Date();

	public Date getCreated() {
		return created;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		WithId other = (WithId) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public String toString() {
		return this.getClass().getSimpleName() + " with id:" + id;
	}
	
	
	
}
